<template>
	<view class="container">
		<view class="header">
			<text class="title">我的收藏</text>
			<text class="count">共{{ collections.length }}个收藏</text>
		</view>
		
		<view class="collection-list">
			<view class="collection-item" v-for="game in collections" :key="game.id" @click="navigateToGameDetail(game.id)">
				<image :src="game.logo" class="game-logo" mode="aspectFill" />
				<view class="game-info">
					<text class="game-name">{{ game.name }}</text>
					<text class="game-desc">{{ game.description }}</text>
					<view class="game-stats">
						<text class="play-count">{{ game.playCount }}人在玩</text>
						<text class="collect-time">收藏于 {{ game.collectTime }}</text>
					</view>
				</view>
				<text class="remove-btn" @click.stop="removeCollection(game.id)">×</text>
			</view>
		</view>
		
		<view class="empty-state" v-if="collections.length === 0">
			<image src="/static/empty-collection.png" mode="aspectFit" class="empty-image" />
			<text class="empty-text">还没有收藏任何游戏哦</text>
		</view>
	</view>
</template>

<script>
import { games } from '../../../utils/gameData.js';

export default {
	data() {
		return {
			collections: []
		}
	},
	created() {
		// 模拟从游戏数据中随机选择几个作为收藏
		this.collections = games.slice(0, 5).map(game => ({
			id: game.game_id,
			name: game.game_name,
			logo: game.game_logo,
			description: game.game_desc,
			playCount: Math.floor(Math.random() * 1000),
			collectTime: this.getRandomDate()
		}));
	},
	methods: {
		navigateToGameDetail(gameId) {
			uni.navigateTo({
				url: `/pages/lobby/gameDetail?id=${gameId}`
			});
		},
		removeCollection(gameId) {
			uni.showModal({
				title: '取消收藏',
				content: '确定要取消收藏该游戏吗？',
				success: (res) => {
					if (res.confirm) {
						this.collections = this.collections.filter(game => game.id !== gameId);
						uni.showToast({
							title: '已取消收藏',
							icon: 'success'
						});
					}
				}
			});
		},
		getRandomDate() {
			const start = new Date(2023, 0, 1);
			const end = new Date();
			const date = new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
			return `${date.getMonth() + 1}月${date.getDate()}日`;
		}
	}
}
</script>

<style scoped>
.container {
	min-height: 100vh;
	background: #1E1E2E;
	padding: 12px;
}

.header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 15px;
	background: #2D2D44;
	border-radius: 6px;
	margin-bottom: 15px;
}

.title {
	font-size: 18px;
	color: #9796B8;
	font-weight: bold;
}

.count {
	font-size: 14px;
	color: #6E6C89;
}

.collection-list {
	background: #2D2D44;
	border-radius: 6px;
	padding: 10px;
}

.collection-item {
	display: flex;
	padding: 15px;
	border-bottom: 1px solid rgba(110, 108, 137, 0.2);
	position: relative;
}

.collection-item:last-child {
	border-bottom: none;
}

.game-logo {
	width: 60px;
	height: 60px;
	border-radius: 6px;
	margin-right: 12px;
}

.game-info {
	flex: 1;
}

.game-name {
	font-size: 16px;
	color: #9796B8;
	margin-bottom: 4px;
}

.game-desc {
	font-size: 12px;
	color: #6E6C89;
	margin-bottom: 8px;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;
}

.game-stats {
	display: flex;
	justify-content: space-between;
	font-size: 12px;
	color: #6E6C89;
}

.remove-btn {
	position: absolute;
	top: 10px;
	right: 10px;
	width: 20px;
	height: 20px;
	line-height: 20px;
	text-align: center;
	color: #6E6C89;
	font-size: 20px;
}

.empty-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 50px 0;
}

.empty-image {
	width: 150px;
	height: 150px;
	margin-bottom: 15px;
}

.empty-text {
	color: #6E6C89;
	font-size: 14px;
}
</style> 